<?php

namespace Buu\Modules\Domain\Apis;

use App\Http\Controllers\Controller;
use Doraemon\service\DomainConfig;
use Illuminate\Http\Request;

class Add extends Controller
{
    public function index(Request $request)
    {
       $requestParams = $request->all();
       $domain_name = $requestParams['domain_name'] ? : '';
       $domain_host = $requestParams['host_json'] ? : '';
       $template_id  = $requestParams['template_id'] ? : 1;
       if(empty($domain_name) || empty($domain_host)){
           return response()->json([
               'code' => 0,
               'msg' => '参数错误'
           ]);
       }
       $domain_host = json_decode($domain_host , true);
       if(!is_array($domain_host)){
           return response()->json([
               'code' => 0,
               'msg' => '参数错误'
           ]);
       }
       $result =  DomainConfig::addDomain($domain_name , $domain_host , $template_id);
       if($result){
           return response()->json([
               'code' => 1,
               'msg' => '添加成功'
           ]);
       }else{
        return response()->json([
            'code' => 0,
            'msg' => '添加失败'
        ]);
       }
    }

}